package connect4client.core;

import java.util.Collection;
import java.util.List;

import connect4client.net.ConnectionController;
import connect4client.net.servers.Server;
import core.PluginInfo;

import messages.InvalidInvitationReceivedMessage;
import messages.InvalidUserDetailsRequestMessage.ErrorCode;
import game.*;

public interface GUIMediator {
	
	
	public void loginSuccessful();
	
	
	public void loginFailed();
	
	
	public void registrationSuccessful();
	
	
	public void registrationFailed();
	
	
	/**
	 * Adds a player to the player's list 
	 */
	public void userLoggedIn(Player player);
	
	
	/**
	 * Removes a player from the player's list
	 */
	public void userLoggedOut(String playerLogin);
	
	
	public void listPlayersReply(List<Player> players);
	
	
	/**
	 * Shows the Wall Message
	 * 
	 * @param playerName The sender's name.
	 * @param message The message's contents
	 */
	public void wall(String senderLogin, String contents);
	
	
	/**
	 * Notifies the user that he just received an invitation
	 * 
	 * @param opponentName The opponent's name
	 * @param gameName The game's name
	 * @param replyId The reply id
	 */
	public void invitationReceived(String opponentName, String gameName, int replyId);


	/**
	 * Notifies the user that a player has accepted his invitation
	 * 
	 * @param opponentName The opponent's name
	 * @param gameName The game's name
	 */
	public void invitationAccepted(final Player opponent, final String gameName);


	/**
	 * Notifies the user that a player denied his invitation
	 * 
	 * @param opponentName The opponent's name
	 * @param gameName The game's name
	 */
	public void invitationDenied(final Player opponent, final String gameName);

	
	public void invalidInvitationReceived(InvalidInvitationReceivedMessage.ErrorCode errorCode);
	
	
	public void invitationTimedOut(String login, String gameType);
	
		
	/**
	 * Starts a new match 
	 * 
	 * @param opponentName The opponent's name
	 * @param gameName The game's name
	 * @param matchId The match id
	 */
	public void matchStarted(Player me, Player opponent, String gameName, int matchId, String nextPlayer);


	/**
	 * Shows a chat message.
	 * 
	 * @param login The sender's login
	 * @param contents The message's contents
	 * @param matchId The match's id
	 */
	public void chat(String login, String contents, int matchId);


	/**
	 * Receives a playerMove and processes its move in the Gui
	 * 
	 * @param playerMove The player move
	 * @param matchId The match's ID
	 * @param nextPlayer The name of the next player.
	 */
	public void playerMove(PlayerMove playerMove, int matchId, String nextPlayer);

	
	public void invalidMove(int matchId);
	
	
	public void giveUp(int matchId);
	
	
	/**
	 * Notifies the user that the match is over
	 * 
	 * @param matchId The match's id
	 * @param winner The winner's name
	 */
	public void matchEnded(int matchId, List<Player> players, String winner);
	
	
	public void matchEndedTied(int matchId, List<Player> players);
	
	
	public void invalidUserDetailsRequest(String login, ErrorCode errorCode);


	public void userDetailsReply(Player player, List<MatchStatistics> oldMatchs, List<MatchStatistics> activeMatchs);


	public void listMatchsReply(List<MatchStatistics> activeMatchs);
	
	
	public void listGamesReply(List<String> games);


	/*
	 * Account management
	 */
	
	public void accountCreationFailed(String adminLogin, String login, messages.AccountCreationFailedMessage.ErrorCode errorCode);


	public void accountCreationSuccessful(String adminLogin, String login);


	public void accountEditionFailed(String adminLogin, String login, messages.AccountEditionFailedMessage.ErrorCode errorCode);


	public void accountEditionSuccessful(String adminLogin, String login);


	public void accountRemotionFailed(String adminLogin, String login, messages.AccountRemotionFailedMessage.ErrorCode errorCode);


	public void accountRemotionSuccessful(String adminLogin, String login);
	
	
	public void listPluginsReply(Collection<PluginInfo> plugins);
	
	
	public void pluginStartupSuccessful(String adminLogin, String pluginName);
	
	
	public void pluginStartupFailed(String adminLogin, String pluginName);
	
	
	public void pluginShutdownSuccessful(String adminLogin, String pluginName);
	
	
	public void pluginShutdownFailed(String adminLogin, String pluginName);


	public void sendLoginMessage(ConnectionController.CommunicationMethod method, Server server, String userName, String password);
	
	
	public void sendRegisterMessage(ConnectionController.CommunicationMethod method, Server server, String userName, String password);
	
	
	public void sendListPlayersMessage(boolean all);
	
	
	/**
	 * Triggered when the user wants to send a message to everyone.
	 * 
	 * @param contents The message's content 
	 */
	public void sendWallMessage(String contents);
	
	
	/**
	 * Triggered when the user wants to invite someone to a new match.
	 * 
	 * @param login The player's login
	 * @param gameName The game's name 
	 */
	public void sendInvitationMessage(String login, String gameName);


	/**
	 * Triggered when the user replies to an invitation.
	 * 
	 * @param login The login of the other player
	 * @param gameName The game's name 
	 */
	public void sendInvitationReplyMessage(int replyId, boolean accepted);
	
	
	/**
	 * Triggered when the user wants to send a message to someone.
	 * 
	 * @param opponent The destiny's login
	 * @param contents The message's content
	 * @param matchId The match's id
	 */
	public void sendChatMessage(String opponent, String contents, int matchId);


	/**
	 * Triggered when the user makes a move.
	 * 
	 * @param matchId The match's id
	 * @param playerMove The PlayerMove containing info about this move.
	 */
	public void sendPlayerMoveMessage(int matchId, PlayerMove playerMove);


	public void sendGiveUpMessage(int matchId);
	
	
	public void sendListMatchsMessage();
	
	
	public void sendUserDetailsMessage(String login);
	
	
	public void sendAccountCreateMessage(String login, String password, String role);
	
	
	public void sendAccountEditMessage(String login, String newPassword, String newRole);
	
	
	public void sendAccountRemoveMessage(String login);
	
	
	public void sendListPluginsMessage();
	
	
	public void sendListGamesMessage();
	
	
	public void sendStartPluginMessage(String pluginName);
	
	
	public void sendStopPluginMessage(String pluginName);
	

	public void sendQuitMessage();
}